<template>
  <div class="home">
    <el-row class="container">
      <el-row :span="24" class="header">
        <el-col :span="10" class="logo" :class="collapsed ? 'logo-collapsed-width' : 'logo-width'">
          {{ collapsed ? '' : 'ADMIN' }}
        </el-col>
        <el-col :span="10">
          <div class="tools" @click.prevent="collapse">
            <svg-icon icon-class="align-justify"></svg-icon>
          </div>
        </el-col>
        <el-col :span="4" class="userinfo">
          <el-dropdown>
            <span class="el-dropdown-link userinfo-inner">{{ sysName }} <svg-icon icon-class="sysUser"></svg-icon></span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item divided>Logout</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
      <el-row :span="24" class="main">
        <aside :class="collapsed ? 'menu-collapsed' : 'menu-expanded'">
          <!-- 导航菜单 -->
          <el-menu :default-active="$route.path" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
            unique-opened router :collapse="collapsed">
            <template v-for="(item, index) in $router.options.routes" v-if="item.ismenu">
              <el-submenu :index="index" :key="index" v-if="!item.leaf">
                <template slot="title">
                  <svg-icon v-bind:icon-class="item.iconCls"></svg-icon>
                  <span slot="title"> {{ item.name }}</span>
                </template>
                <!-- 子菜单 -->
                <el-menu-item v-for="(child, childindex) in item.children" :key="childindex" :index="item.children[0].path">
                  <svg-icon v-bind:icon-class="child.iconCls"></svg-icon>
                  <span slot="title"> {{ child.name }}</span>
                </el-menu-item>
              </el-submenu>
              <el-menu-item v-if="item.leaf&&item.children.length>0" :key="index" :index="item.children[0].path">
                <svg-icon v-bind:icon-class="item.iconCls"/>
                <span slot="title"> {{ item.children[0].name }}</span>
              </el-menu-item>
            </template>
          </el-menu>
        </aside>
        <!-- 主体内容 -->
        <section class="content-container">
          <div class="grid-content bg-purple-light">
            <el-col class="breadcrumb-container">
              <strong class="title">{{$route.name}}</strong>
              <el-breadcrumb class="breadcrumb-inner" separator="/">
                <el-breadcrumb-item v-for="item in $route.matched" :key="item.path">
                  {{ item.name }}
                </el-breadcrumb-item>
              </el-breadcrumb>
            </el-col>
            <el-col :span="24" class="content-wrapper">
              <transition name="fade" mode="out-in">
                <router-view></router-view>
              </transition>
            </el-col>
          </div>
        </section>
      </el-row>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'home',
  data() {
    return {
      collapsed: false,
      sysName: 'Admin'
    }
  },
  methods: {
    handleOpen() { },
    handleClose() { },
    collapse() {
      this.collapsed = !this.collapsed
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  .header {
    background: #20a0ff;
    height: 60px;
    line-height: 60px;
    color: #fff;
    .logo {
      font-size: 22px;
      padding-left: 20px;
      padding-right: 20px;
      border-right: 1px solid rgba(238, 241, 146, 0.3);
    }
    .logo-width {
      width: 230px;
    }
    .logo-collapsed-width {
      width: 65px;
      height: 60px;
    }
    .tools {
      padding: 0 23px;
      width: 14px;
      height: 60px;
      cursor: pointer;
    }
    .userinfo {
      text-align: right;
      padding-right: 35px;
      float: right;
      .userinfo-inner {
        cursor: pointer;
        color: #fff;
        svg {
          font-size: 40px;
          margin: 10px 0 10px 10px;
          float: right;
        }
      }
    }
  }
  .main {
    display: flex;
    position: absolute;
    width: 100%;
    top: 60px;
    bottom: 0px;
    overflow: hidden;
    aside {
      flex: 0 0 230px;
      width: 230px;
      .el-menu{
        height: 100%;
      }
      .collapsed{
        width: 60px;
        .item{
          position: relative;
        }
        .submenu{
          position: absolute;
          top: 0;
          left: 60px;
          z-index: 99999;
          height: auto;
          display: none;
        }
      }
    }
    .menu-collapsed {
      flex: 0 0 60px;
      width: 60px;
    }
    .menu-expanded {
      flex: 0 0 230px;
      width: 230px;
    }
    .content-container{
      flex: 1;
      overflow-y: scroll;
      padding: 20px;
      .breadcrumb-container{
        .title{
          width: 200px;
          float: left;
          color: #475669;
        }
        .breadcrumb-inner{
          float: right;
        }
      }
      .content-wrapper{
        background-color: #fff;
        box-sizing: border-box;
        padding: 10px 0;
      }
    }
  }
}
</style>


